package com.yphone.ui.login.manager;

import android.text.TextUtils;

import com.iiordanov.bVNC.App;
import com.yphone.base.utils.MySharepreferenceUtil;
import com.yphone.base.utils.SharepreferenceUtils;
import com.yphone.tools.SharepreferenConstants;
import com.yphone.ui.login.respone.UserInfo;

public class LoginManager {
    private UserInfo mInfo;

    public String getToken() {
        if (mInfo!=null){
            return mInfo.token;
        }
        return null;
    }

    private static class LazyHolder {
        /* access modifiers changed from: private */
        public static final LoginManager INSTANCE = new LoginManager();

        private LazyHolder() {
        }
    }

    private LoginManager() {
        this.mInfo = null;
    }

    public static LoginManager getInstance() {
        return LazyHolder.INSTANCE;
    }

    public boolean isLogin() {
        UserInfo info = getInfo();
        if (info != null && !TextUtils.isEmpty(info.token)) {
            return true;
        }
        return false;
    }

    public void saveInfo(UserInfo userInfo){
        SharepreferenceUtils.saveClass(App.getContext(), SharepreferenConstants.SHARE_NAME_FILE, SharepreferenConstants.USER_INFO_NODE, userInfo);
    }

    public UserInfo getInfo() {
        try {
            if (this.mInfo == null) {
                this.mInfo = (UserInfo) SharepreferenceUtils.jsonToClass(App.getContext(), SharepreferenConstants.SHARE_NAME_FILE, SharepreferenConstants.USER_INFO_NODE);
            }
            return this.mInfo;
        } catch (Exception e) {
            return null;
        }
    }

    public void clearUserInfo() {
        MySharepreferenceUtil.putSharePreStr(App.getContext(), SharepreferenConstants.SHARE_NAME_FILE, SharepreferenConstants.USER_INFO_NODE, "");
        this.mInfo = null;
    }


}